class Solution:
    def minimizeMax(self, nums: List[int], p: int) -> int:
        nums.sort()

        def f(x):
            i, j = 0, 0
            while i < len(nums) - 1:
                if nums[i + 1] - nums[i] <= x:
                    i += 2
                    j += 1
                else:
                    i += 1
            return True if j >= p else False

        return bisect_left(range(nums[-1] - nums[0]), True, key = f)